﻿/* Write a program that finds the maximal sequence of equal elements in an array.
		Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1}  {2, 2, 2}. */

using System;

namespace MaxSequenceOfEqualElements
{
    class MaxSequenceOfEqualElements
    {
        static void Main()
        {
            int[] testArray = { 2, 1, 1, 2, 3, 3, 2, 2, 2, 1 }; //

            int count = 1;
            int bestCount = 1;
            int bestNum = 0;

            for (int i = 0; i < testArray.Length - 1; i++)
            {
                if (testArray[i] == testArray[i + 1])
                {
                    count++;

                    if (count >= bestCount)
                    {
                        bestCount = count;
                        bestNum = testArray[i];
                    }
                }
                else
                {
                    count = 1;
                }
            }
            Console.WriteLine("Maximal sequence of equal elements in this array is: {0}\n\r", bestCount);

            Console.Write("{");
            for (int i = 0; i < bestCount; i++)
            {
                if (i + 1 < bestCount)
                {
                    Console.Write("{0},", bestNum);
                }
                else
                {
                    Console.Write("{0}", bestNum);
                }
            }
            Console.Write("}\n\r\n\r");
        }
    }
}
